<?php
header("content-type:text/html;charset=utf-8");
require_once("../data/common.inc.php");
$char="utf8";
$link=mysqli_connect('127.0.0.1', $cfg_dbuser, $cfg_dbpwd);
mysqli_select_db($link,$cfg_dbname);
mysqli_set_charset($link,$char);
$type=$_REQUEST['type'];
$keyword=$_REQUEST['keyword'];
$page=$_GET['page']?$_GET['page']:1;
$top=$page<2?1:$page-1;
$next=$page+1;
$pagesize=10;

if($type=='' || $keyword==''){
	$sql1 = "select count(*) from wzwa_saveimg";
	$re= mysqli_query($link,$sql1);
	$rowcount = mysqli_fetch_assoc($re);
	$totalpage = ceil($rowcount["count(*)"]/$pagesize);
	
	if($page>=$totalpage){
		$page=$totalpage;
		$next=$totalpage;
	}
	$start=($page-1)*$pagesize;	
	
	$sql = "select * from wzwa_saveimg limit $start,$pagesize"; 
	$re= mysqli_query($link,$sql);
	$arr =array();
	while($row=mysqli_fetch_assoc($re)){
		$arr[]=$row;
	}
}else{
	$sql1 = "select count(*) from wzwa_saveimg where $type like '%{$keyword}%'";
	$re= mysqli_query($link,$sql1);
	$rowcount = mysqli_fetch_assoc($re);
	$totalpage = ceil($rowcount["count(*)"]/$pagesize);
	
	if($page>=$totalpage){
		$page=$totalpage;
		$next=$totalpage;
	}
	$start=($page-1)*$pagesize;	
	
	$sql = "select * from wzwa_saveimg where $type like '%{$keyword}%' limit $start,$pagesize"; 
	$re= mysqli_query($link,$sql);
	$arr =array();
	while($row=mysqli_fetch_assoc($re)){
		$arr[]=$row;
	}
}
mysqli_free_result($re);
mysqli_close($link);
?>
<html>
	<head>
		<meta charset="UTF-8">
		<title>see_save</title>
		<style type="text/css">
			.tab{width: 80%;margin: 50 auto;}
			.tab table{width: 100%;}
			.tab td{text-align: center;}
		</style>
	</head>
	<body>
<div class="tab">
	<form action="#" method="post">
		<select name="type">
			<option value="id">ID</option>
			<option value="save">save</option>
			<option value="savetime">savetime</option>
		</select>
		keyword:<input type="text" name="keyword" value="" />
		<input type="submit" value="search"/>
	</form>
	<table border="1" cellspacing="0" cellpadding="0">
		<tr>
			<th>ID</th>
			<th>save</th>
			<th>savetime</th>
		</tr>
<?php
foreach($arr as $v){
?>			
		<tr>
			<td><?php echo $v['id'];?></td>
			<td><?php echo $v['save'];?></td>
			<td><?php echo $v['savetime'];?></td>
		</tr>
<?php
}
?>	
		<tr>
			<td colspan="10">
				<form action="#" method="get">
				<a href="see_save.php">index</a>
				<a href="see_save.php?page=<?php echo $top; ?>&type=<?php echo $type;?>&keyword=<?php echo $keyword;?>">top</a>
				<a href="see_save.php?page=<?php echo $next; ?>&type=<?php echo $type;?>&keyword=<?php echo $keyword;?>">next</a>
				<a href="see_save.php?page=<?php echo $totalpage; ?>&type=<?php echo $type;?>&keyword=<?php echo $keyword;?>">end</a>
				&nbsp;&nbsp;<span>now is <?php echo $page; ?>page</span>
				&nbsp;&nbsp;<span>all:<?php echo $totalpage; ?>page</span>
				get to:<input type="text" name="page" />
				<input type="submit" value="Go" />
				</form>
			</td>
		</tr>		
	</table>
</div>
	</body>
</html>



